srcdir=src/*/
objdir=obj/
bindir=lib/
includedir=src/
includeLibs=externLibs/
CXX=g++
CXXFLAGS=-fPIC -Wall -DGLEW_BUILD -s -O2
LDFLAGS=-LexternLibs/unix -lglfw -lGL -lGLU -lSOIL #-lpthread
EXE=libXBlue3D.so
SRC= $(wildcard $(srcdir)*.cpp)
OBJ= $(SRC:%.cpp=$(objdir)%.o)

all: depend $(EXE)

$(EXE): $(OBJ)
	$(CXX) -o obj/externLibs/glew.o -c externLibs/GL/glew.c $(CXXFLAGS) -I$(includeLibs) -DGLEW_STATIC
	$(CXX) -shared -o $(bindir)$@ $^ obj/externLibs/glew.o $(LDFLAGS) $(CXXFLAGS)

depend: 
	$(CXX) -MM $(SRC) >depend

-include depend

$(objdir)%.o: %.cpp
	$(CXX) -o $@ -c $< $(CXXFLAGS) -I$(includedir) -I$(includeLibs)

.PHONY: install clean cleaninstall mrproper

install:
	rm -rf /usr/lib/XBlue3D
	mkdir /usr/lib/XBlue3D
	cp lib/libXBlue3D.so /usr/lib/XBlue3D/
	rm -rf /usr/include/XBlue3D
	cp -r src/ /usr/include/XBlue3D
	rm -rf /usr/lib/libXBlue3D.so*
	ln -s /usr/lib/XBlue3D/libXBlue3D.so /usr/lib/libXBlue3D.so
	ldconfig

clean:
	rm -rf $(objdir)*/*.o
	rm -rf $(objdir)*/*/*.o

cleaninstall:
	rm -rf /usr/lib/XBlue3D
	rm -rf /usr/include/XBlue3D
	rm -rf /usr/lib/libXBlue3D.so*

mrproper: clean
	rm -rf $(bindir)$(EXE)
	rm -rf $(includedir)*/*~
	rm -rf $(srcdir)*~
	rm -rf *~
